<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>数组扁平化</title>
</head>
<body>
<script>
function flatten (arr) {
	let result = [];

	for(let i = 0; i < arr.length; i++) {
		if(Array.isArray(arr[i])) {
			result = result.concat(flatten(arr[i]));
		} else {
			result.push(arr[i]);
		}
	}
	return result;
}
const a = [1, [2, [3, 4]]];
console.log(flatten(a));//[1,2,3,4]
</script>
</body>
</html>